package com.grgbanking.it.system.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.grgbanking.it.base.BaseDao;
import com.grgbanking.it.system.dao.IMUserRoleDao;
import com.grgbanking.it.system.entity.MUserRole;


/**
 * 用户角色中间表DAO
 * 
 * IMUserRoleDao
 * 
 * @author 潘广伟
 * @Email p_3er@qq.com
 * @Date 2014-12-18 上午10:26:36
 * 
 * @version 1.0.0
 *
 */
@Repository 
public class MUserRoleDao extends BaseDao<MUserRole, Integer> implements IMUserRoleDao<MUserRole, Integer> { 
    @Autowired  
    public void setMySessionFactory(SessionFactory sessionFactory){  
        super.setSessionFactory(sessionFactory);  
    }

    /**
	 * 获取所有工程师用户名
	 * getEnginnerUsernams
	 * 
	 * @return
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	@Override
	public List<String> getEnginnerUsernams() throws Exception {
		String sql = "select m.username from m_user_role m where m.role_id in(select r.id from role r where r.name='IT工程师')";
		List<Map> list = this.listBySQL(sql);
		List<String> usernames = new ArrayList<String>();
		for(Map map : list){
			usernames.add(map.get("username").toString());
		}
		return usernames;
	}
    
  
}